import axios from '@/api/interceptor';
import { ArticleData } from '@/api/article/types';

export const selectPageArticle = async (params: any) => {
  const result = await axios({
    url: '/article/listPage',
    method: 'GET',
    params,
  });
  return result.data;
};

export const publishArticles = async (ids: number[]) => {
  const result = await axios({
    url: '/article/publish',
    method: 'POST',
    data: ids,
  });
  return result.data;
};

export const archivedArticles = async (ids: number[]) => {
  const result = await axios({
    url: '/article/archived',
    method: 'POST',
    data: ids,
  });
  return result.data;
};

export const createArticle = async (data: ArticleData) => {
  const result = await axios({
    url: '/article/createArticle',
    method: 'POST',
    data,
  });
  return result.data;
};

export const removeArticle = async (ids: number[]) => {
  const result = await axios({
    url: '/article/removeArticle',
    method: 'DELETE',
    data: ids,
  });
  return result.data;
};

export const getArticleDetail = async (id: number) => {
  const result = await axios({
    url: '/article/getArticleDetail',
    method: 'GET',
    params: { id },
  });
  return result.data;
};

export const editArticle = async (data: ArticleData) => {
  const result = await axios({
    url: '/article/editArticle',
    method: 'PUT',
    data,
  });
  return result.data;
};
